/*
 * File: E:\Kan\ARM\Projects\Google Code\Umrichter\trunk\SimulinkModelle\slprj\ert\_sharedutils\binsearch_u32u16_prevIdx.c
 *
 * Code generated for Simulink model 'Fu_Foc'.
 *
 * Model version                  : 1.270
 * Simulink Coder version         : 8.2 (R2012a) 29-Dec-2011
 * TLC version                    : 8.2 (Dec 29 2011)
 * C/C++ source code generated on : Sun Apr 28 18:42:25 2013
 */

#include "rtwtypes.h"
#include "rtw_shared_utils.h"

uint32_T binsearch_u32u16_prevIdx(uint16_T u, const uint16_T bp[], uint32_T
  startIndex, uint32_T maxIndex)
{
  uint32_T iRght;
  uint32_T iLeft;
  uint32_T bpIdx;
  uint32_T found;

  /* Binary Search using Previous Index */
  bpIdx = startIndex;
  iLeft = 0U;
  iRght = maxIndex;
  found = 0U;
  while (found == 0U) {
    if (u < bp[bpIdx]) {
      iRght = bpIdx - 1U;
      bpIdx = (iRght + iLeft) >> 1U;
    } else if (u < bp[bpIdx + 1U]) {
      found = 1U;
    } else {
      iLeft = bpIdx + 1U;
      bpIdx = (iRght + iLeft) >> 1U;
    }
  }

  return bpIdx;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
